const { contextBridge, ipcRenderer } = require('electron');

// 暴露安全的API给渲染进程
contextBridge.exposeInMainWorld('electronAPI', {
  // 获取应用版本
  getAppVersion: () => ipcRenderer.invoke('get-app-version'),
  
  // 文件对话框
  showSaveDialog: (options) => ipcRenderer.invoke('show-save-dialog', options),
  showOpenDialog: (options) => ipcRenderer.invoke('show-open-dialog', options),
  
  // 服务器管理
  restartServer: () => ipcRenderer.invoke('restart-server'),
  
  // 平台信息
  platform: process.platform,
  
  // 检查是否在Electron环境中
  isElectron: true
});

// 暴露Node.js路径模块的安全版本
contextBridge.exposeInMainWorld('pathAPI', {
  join: (...args) => require('path').join(...args),
  dirname: (path) => require('path').dirname(path),
  basename: (path) => require('path').basename(path),
  extname: (path) => require('path').extname(path)
});